<template>
  <view class="nav-bar">
    <view class="nav-left" @click="goBack">
      <uni-icons type="back" size="24"></uni-icons>
    </view>
    <view class="nav-title">{{ title }}</view>
    <view class="nav-right">
      <view class="nav-right-item" v-if="showShare">
        <uni-icons type="redo" size="24" @click="onShare"></uni-icons>
      </view>
      <view class="nav-right-item" v-if="showSearch">
        <uni-icons type="search" size="24" @click="onSearch"></uni-icons>
      </view>
    </view>
  </view>
</template>

<script>
export default {
  name: 'NavBar',
  props: {
    title: {
      type: String,
      required: true
    },
    showSearch: {
      type: Boolean,
      default: false
    },
    showShare: {
      type: Boolean,
      default: false
    }
  },
  methods: {
    goBack() {
      uni.navigateBack();
    },
    onSearch() {
      this.$emit('search');
    },
    onShare() {
      this.$emit('share');
    }
  }
};
</script>

<style lang="scss">
.nav-bar {
  display: flex;
  align-items: center;
  height: 90rpx;
  background-color: #fff;
  padding: 0 30rpx;
  position: relative;
  
  .nav-left {
    position: absolute;
    left: 30rpx;
    height: 100%;
    display: flex;
    align-items: center;
  }
  
  .nav-title {
    flex: 1;
    text-align: center;
    font-size: 32rpx;
    font-weight: bold;
    position: absolute;
    left: 50%;
    transform: translateX(-50%);
  }

  .nav-right {
    position: absolute;
    right: 30rpx;
    height: 100%;
    display: flex;
    align-items: center;
  }
}
</style>